package com.bian.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class MapperFactory {

    // 静态变量来存储ApplicationContext
    private static ApplicationContext applicationContext;

    // 通过Autowired注入ApplicationContext
    @Autowired
    public void setApplicationContext(ApplicationContext applicationContext) {
        MapperFactory.applicationContext = applicationContext;
    }

    // 静态方法来获取Mapper
    public static <T> T getMapper(Class<T> mapperClass) {
        return applicationContext.getBean(mapperClass);
    }
}
